import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    // 布局
    path: '/',
    name: 'layout',
    redirect: '/role',
    component: () => import(/* webpackChunkName: "layout" */ '../views/layout'),
    children: [
      // 角色
      {
        path: '/role',
        name: 'role',
        meta: { title: '角色管理' },
        component: () => import(/* webpackChunkName: "role" */ '../views/role')
      },
      // 角色权限分配
      {
        path: '/role/:id/alloc-menu',
        name: 'alloc-menu',
        meta: { title: '角色权限管理' },
        component: () =>
          import(
            /* webpackChunkName: "alloc-menu" */ '../views/role/alloc-menu'
          ),
        props: true
      },
      // 菜单
      {
        path: '/menu',
        name: 'menu',
        meta: { title: '菜单管理' },
        component: () => import(/* webpackChunkName: "menu" */ '../views/menu')
      },
      // 添加或编辑菜单
      {
        path: '/add-or-edit',
        name: 'add-or-edit',
        meta: { title: '菜单更新' },
        component: () =>
          import(
            /* webpackChunkName: "add-or-edit" */ '../views/menu/add-or-edit'
          )
      },
      // 资源
      {
        path: '/resource',
        name: 'resource',
        meta: { title: '资源管理' },
        component: () =>
          import(/* webpackChunkName: "resource" */ '../views/resource')
      },
      // 课程
      {
        path: '/course',
        name: 'course',
        meta: { title: '课程管理' },
        component: () =>
          import(/* webpackChunkName: "course" */ '../views/course')
      },
      // 课程内容管理
      {
        path: '/section/:id',
        name: 'section',
        props: true,
        meta: { title: '课程内容管理' },
        component: () =>
          import(
            /* webpackChunkName: "section" */ '../views/course/section.vue'
          )
      },
      // 新增课程
      {
        path: '/update-course',
        name: 'update-course',
        meta: { title: '新增课程' },
        component: () =>
          import(
            /* webpackChunkName: "update-course" */ '../views/course/update-course.vue'
          )
      },
      // 编辑课程
      {
        path: '/edit-course/:courseId',
        name: 'edit-course',
        meta: { title: '编辑课程' },
        props: true,
        component: () =>
          import(
            /* webpackChunkName: "edit-course" */ '../views/course/edit-course.vue'
          )
      },
      // 上传课时视频
      {
        path: '/edit-lesson',
        name: 'edit-lesson',
        meta: { title: '课时视频上传' },
        props: true,
        component: () =>
          import(
            /* webpackChunkName: "edit-lesson" */ '../views/course/edit-lesson.vue'
          )
      },
      // 用户管理
      {
        path: '/user',
        name: 'user',
        meta: { title: '用户管理' },
        component: () => import(/* webpackChunkName: "user" */ '../views/user')
      },
      // 广告
      {
        path: '/ads',
        name: 'ads',
        meta: { title: '广告管理' },
        component: () => import(/* webpackChunkName: "ads" */ '../views/ads')
      },
      // 新增广告
      {
        path: '/add-ads',
        name: 'add-ads',
        meta: { title: '新增广告' },
        component: () =>
          import(/* webpackChunkName: "add-ads" */ '../views/ads/add-ads.vue')
      },
      // 编辑广告
      {
        path: '/edit-ads/:id',
        name: 'edit-ads',
        meta: { title: '更新广告' },
        props: true,
        component: () =>
          import(/* webpackChunkName: "edit-ads" */ '../views/ads/edit-ads.vue')
      },
      // 广告位
      {
        path: '/ads-space',
        name: 'ads-space',
        meta: { title: '广告位管理' },
        component: () =>
          import(/* webpackChunkName: "ads-space" */ '../views/ads-space')
      },
      // 新增广告位
      {
        path: '/add-space',
        name: 'add-space',
        meta: { title: '新增广告位' },
        component: () =>
          import(
            /* webpackChunkName: "add-space" */ '../views/ads-space/add-space.vue'
          )
      },
      // 编辑广告位
      {
        path: '/edit-space/:id',
        name: 'edit-space',
        props: true,
        meta: { title: '编辑广告位' },
        component: () =>
          import(
            /* webpackChunkName: "edit-space" */ '../views/ads-space/edit-space.vue'
          )
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import(/* webpackChunkName: "login" */ '../views/login')
  },
  {
    path: '*',
    name: 'error-page',
    component: () =>
      import(/* webpackChunkName: "error-page" */ '../views/error-page')
  }
]

const router = new VueRouter({
  // mode: "history",
  base: process.env.BASE_URL,
  routes
})
// router.beforeEach()
export default router
